/**
 * Created by WYH on 17/4/20.
 */
angular.module('tribalc').service(
    'RentProtocolModel',
    ['TimeFormat', function (TimeFormat) {


        var RentProtocol = function (object) {
            var self = this;

            init();

            function init() {
                if (object) {
                    self.id = object.id || null;
                    self.communityId = object.communityId || null;
                    self.companyId = object.ownerId || null;
                    self.createTime = object.createTime || 0;
                    self.roomNum = object.roomNum || '';
                    self.monthlyRent = object.monthlyRent || 0;
                    self.payCycle = object.payCycle || 0;
                    self.beginTime = object.beginTime || 0;
                    self.endTime = object.endTime || 0;
                    self.imminentPayTime = object.imminentPayTime || 0;
                    self.rentStatus = object.rentStatus || null;
                    self.renewed = object.renewed || null;
                    self.companyName = object.companyName || '';
                    self.lockAuthorized = object.lockAuthorized || false;
                    self.status = object.status || null;
                    // self.type = "OFFICE";
                }
            }
        };


        /* 缴租状态 */
        RentProtocol.Status = {
            'confirm': 'CONFIRM',  //待确认
            'overdue': 'OVERDUE',  //逾期
            'normal': 'NORMAL'  //正常
        };

        /* 租赁协议状态 */
        RentProtocol.ProtocolStatus = {
            'actived': 'ACTIVED',  //生效中或有欠缺
            'finished': 'FINISHED',  //已完成未欠款
            'inactived': 'INACTIVED'  //尚未生效
        };


        RentProtocol.prototype.getObject = function () {
            return {
                id: this.id,
                communityId: this.communityId,
                companyId: this.companyId,
                createTime: this.createTime,
                roomNum: this.roomNum,
                monthlyRent: this.monthlyRent,
                payCycle: this.payCycle,
                beginTime: this.beginTime,
                endTime: this.endTime,
                imminentPayTime: this.imminentPayTime,
                rentStatus: this.rentStatus,
                renewed: this.renewed,
                companyName: this.companyName,
                lockAuthorized: this.lockAuthorized
            }
        };

        RentProtocol.prototype.getCreateObject = function () {
            return {
                ownerId: this.ownerId,
                roomNum: this.roomNum,
                monthlyRent: parseFloat(this.monthlyRent),
                payCycle: this.payCycle,
                beginTime: this.beginTime,
                endTime: this.endTime,
                imminentPayTime: this.beginTime,
                type: this.type
            }

        };



        RentProtocol.prototype.setupCreateTime = function (str) {
            this.createTime = TimeFormat.changeYearTimeToInt(str);
        };

        RentProtocol.prototype.setupBeginTime = function (str) {
            this.beginTime = TimeFormat.changeYearTimeToInt(str);
        };

        RentProtocol.prototype.setupEndTime = function (str) {
            this.endTime = TimeFormat.changeYearTimeToInt(str);
        };

        RentProtocol.prototype.setupImminentPayTime = function (str) {
            this.imminentPayTime = TimeFormat.changeYearTimeToInt(str);
        };


        RentProtocol.prototype.getCreateTime = function () {
            return this.createTime ? TimeFormat.changeIntToYearTime(this.createTime) : '';
        };

        RentProtocol.prototype.getBeginTime = function () {
            return this.beginTime ? TimeFormat.changeIntToYearTime(this.beginTime) : '';
        };

        RentProtocol.prototype.getEndTime = function () {
            return this.endTime ? TimeFormat.changeIntToYearTime(this.endTime) : '';
        };

        RentProtocol.prototype.getBeginTimeString = function () {
            return this.beginTime ? TimeFormat.changeIntToYearTime(this.beginTime, '-') : '';
        };

        RentProtocol.prototype.getEndTimeString = function () {
            return this.endTime ? TimeFormat.changeIntToYearTime(this.endTime, '-') : '';
        };


        RentProtocol.prototype.getImminentPayTime = function () {
            return this.imminentPayTime ? TimeFormat.changeIntToYearTime(this.imminentPayTime) : '';
        };

        RentProtocol.prototype.getRentStatusStr = function () {
            return {
                'CONFIRM': '待确认',
                "OVERDUE": '逾期',
                "NORMAL": '正常'
            }[this.rentStatus];
        };


        RentProtocol.setupRentProtocolList = function (array) {
            var rentList = [];
            array.forEach(function (value) {
                var rent = new RentProtocol(value);
                rentList.push(rent);
            });
            return rentList;
        };

        return RentProtocol;


    }]
);